namespace Maple.Branch.Identity.Entities
{
    using System;
    using System.Security.Claims;
    using JetBrains.Annotations;
    using Volo.Abp;
    using Volo.Abp.Domain.Entities;
    using Volo.Abp.MultiTenancy;

    public class IdentityClaim : Entity<Guid>, IMultiTenant
    {
        public Guid? TenantId { get; protected set; }

        public string ClaimType { get; protected set; }

        public string ClaimValue { get; protected set; }

        protected IdentityClaim()
        {
        }

        protected internal IdentityClaim(Guid id, [NotNull] Claim claim, Guid? tenantId)
            : this(id, claim.Type, claim.Value, tenantId)
        {
        }

        protected internal IdentityClaim(Guid id, [NotNull] string claimType, string claimValue, Guid? tenantId)
        {
            Check.NotNull(claimType, nameof(claimType));

            Id = id;
            ClaimType = claimType;
            ClaimValue = claimValue;
            TenantId = tenantId;
        }

        public Claim ToClaim()
        {
            return new Claim(ClaimType, ClaimValue);
        }

        public void SetClaim([NotNull] Claim claim)
        {
            Check.NotNull(claim, nameof(claim));

            ClaimType = claim.Type;
            ClaimValue = claim.Value;
        }
    }
}
